package com.example.controller;

import com.example.annotation.AsyncMessageHandler;
import com.example.entity.School;
import com.example.service.SchoolService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/school")
@Tag(name = "学校管理")
public class SchoolController {
    @Autowired
    private SchoolService schoolService;

    @PutMapping
    @Operation(summary = "新增或修改学校信息")
    @PreAuthorize("hasRole('ADMIN') or hasRole('SUPER_ADMIN')")
    @AsyncMessageHandler(queue = "school.update.queue")
    public boolean updateSchool(@RequestBody School school) {
        return schoolService.updateSchool(school);
    }

    @PutMapping("/{id}/canteen")
    @Operation(summary = "更新学校食堂")
    @PreAuthorize("hasRole('ADMIN') or hasRole('SUPER_ADMIN')")
    @AsyncMessageHandler(queue = "school.canteen.queue")
    public boolean updateCanteen(@PathVariable Long id, @RequestParam String canteenUuid) {
        return schoolService.addCanteen(id, canteenUuid);
    }

    @DeleteMapping("/{schoolId}/canteen")
    public boolean removeCanteen(@PathVariable Long schoolId, @RequestParam String canteenUuid) {
        return schoolService.removeCanteen(schoolId, canteenUuid);
    }
} 